#include "Load_Node_twist.h"

#include "Node_Base.h"

#include "Section_beam_BT.h"

#include "Element_Base.h"

void Load_Node_twist::getLoad(std::ifstream& fin)
{
	Load_coord.resize(2);
	fin >> m_Direction >> m_Value >> Load_coord[0] >> Load_coord[1];
}

void Load_Node_twist::coutLoad()
{
	std::cout << m_id << " " << m_pElement.lock()->m_id << " " << m_pNode.lock()->m_id << " " << m_Direction << " " << m_Value << " " << Load_coord[0] << " " << Load_coord[1] << std::endl;
}

void Load_Node_twist::foutLoad(std::ofstream& fout)
{

}

void Load_Node_twist::Assemble(Eigen::VectorXd& F1, Eigen::VectorXd& F2)
{
	std::vector<double> Load_coord_o;
	Load_coord_o.resize(2);
	Load_coord_o[0] = m_pElement.lock()->m_pSection.lock()->coord_c[0] + m_pElement.lock()->m_pSection.lock()->coord_s1[0];
	Load_coord_o[1] = m_pElement.lock()->m_pSection.lock()->coord_c[1] + m_pElement.lock()->m_pSection.lock()->coord_s1[1];
	double Feq = m_Value * (Load_coord[(m_Direction + 1) % 2] - Load_coord_o[(m_Direction + 1) % 2]);
	int m_Fixed = F1.size();
	int DOF = m_pNode.lock()->m_DOF[0];
	if (DOF < m_Fixed)
	{
		F1[DOF] = Feq;
	}
	else
	{
		F2[DOF - m_Fixed] = Feq;
	}
}
